package com.manager.customer.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.manager.common.result.Result;
import com.manager.customer.service.CustomerCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/customer")
@Api(description = "客户管理")
@CrossOrigin(origins = "*")
public class CustomerController {

    @Autowired
    private CustomerCustomerService customerService;

    @ApiOperation(value = "导入客户信息")
    @PostMapping("/import")
    public Result importCustomer(MultipartFile file,
                                 @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date beginTime,
                                 @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date endTime) {
        customerService.importCustomer(file,beginTime,endTime);
        return Result.ok();
    }

    @ApiOperation(value="导出客户信息")
    @GetMapping("/export")
    public void exportCustomer(HttpServletResponse response){
        customerService.exportCustomer(response);
    }

    @ApiOperation(value = "分页查询客户信息")
    @GetMapping("/page")
    public Result<Page> getPage(int page,int pageSize,Integer id,String name,String city){
        return customerService.getPage(page,pageSize,id,name,city);
    }

    @ApiOperation(value = "批量删除客户")
    @DeleteMapping("/delete/more")
    public Result<String> deleteCusByIds(@RequestParam List<Integer> ids){
        return customerService.deleteSellers(ids);
    }
}
